﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>政策法规维护</title>
    <link rel="stylesheet" href="css/table1.css">
    <link rel="stylesheet" href="css/mulu.css">
    <link rel="stylesheet" href="css/element.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/0_common/bootstrap-table.css">
    <script src="css/jquery.min.js"></script>
    <script src="css/vue.js"></script>
    <script src="css/element.js"></script>
    <script src="js/table.js"></script>
    <script src="js/0_common/bootstrap.min.js"></script>
    <script src="js/0_common/bootstrap-table.js"></script>
    <script src="js/constants.js"></script>
    <script src="js/YZidCard.js"></script>

</head>
<body>
<div class="dqy"><span>当前页：政策法规</span></div>
<div id="dhmenu">
    <div id="add"><div class="caozuobox"><img src="img/table/add.png"></div><div class="caozuobox"><span>新增</span></div></div>
    <div id="update"><div class="caozuobox"><img src="img/table/update.png"></div><div class="caozuobox"><span>修改</span></div></div>
    <div id="delete"><div class="caozuobox"><img src="img/table/delete.png"></div><div class="caozuobox"><span>删除</span></div></div>
    <button id="btn_search"></button>
    <input id="key" class="form-control" style="width:15%;height:23px;float:right;margin-top:0.8%;margin-right: 2%"  placeholder="请输入标题"/>
</div>
<div id="mainbox">
    <div id="titlebox"><span>政策法规</span></div>
    <div id="tabletopbox">
        <div class="tishibox"><img src="img/tishi.png"></div>
        <div class="tishibox"><span style="margin-left: 10px">查询结果(共</span><span id="number"></span><span>条信息)</span></div>
    </div>
    <div id="tablebox">
        <table id="table"
               data-toolbar="#toolbar"
               data-show-export="true"
               data-pagination="false"
               data-page-list="[10, 25, 50, 100, ALL]"
               data-id-field="id"
               data-side-pagination="server"
               data-url="../action"
               data-query-params="queryParams"
               data-query-params-type="limit">
        </table>
    </div>
</div>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 70vw;">
    <div class="modal-dialog" style="width: 70vw">
        <div class="modal-content" style="border-radius: 15px;width: 100%;">
            <div class="modal-header" style="background-color:white;color: black;border-top-left-radius: 15px;border-top-right-radius: 15px">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">政策法规新增</h4>
            </div>

            <div class="modal-body" style="width: 100%;float:left;background-color: #F3F3F3;height: auto" id="xq">
                <ul class="nav nav-tabs" role="tablist">
                    <li class="nav-item active">
                        <a class="nav-link active" data-toggle="tab" href="#basic" style="background-color:#F3F3F3" onclick="clean()">政策文件上传</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" data-toggle="tab" href="#process" style="background-color:#F3F3F3" onclick="clean()">政策链接新增</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div id="basic" class="container tab-pane active" style="margin-top:3%;width: 100%;height: auto;color:black">
                        <div class="hangz">
                            <span class="hangtitle">标题</span><br>
                            <input id="name" class="hanginputz"/>
                        </div>
                        <div class="hangz">
                            <span class="hangtitle">政策文件</span><br>
                            <input id="wenjian" class="hanginput" style="width: 73%!important;"/>
                            <input type="file" name="excelFile" id="excelFile" style="display:none" multiple="multiple" onchange="fileUpload()">
                            <button id="glzmbtn" onclick="selectFile()" style="float: right;margin-top: 7px;width: 20%;margin-right: 5%" class="btn">点击上传</button>
                        </div>
                        <div class="hangz">
                            <span class="hangtitle">发布时间</span><br>
                            <input id="fabushijian" class="hanginputz" type="date"/>
                            <!-- <div class="hanginputz" style="border: none"><el-date-picker id="fabushijian" style="width: 100%" v-model="value1" type="datetime" placeholder="选择日期时间"></el-date-picker></div>-->
                        </div>
                    </div>
                    <div id="process" class="container tab-pane fade" style="margin-top:3%;width: 100%;height: auto">
                        <div class="hangz">
                            <span class="hangtitle">标题</span><br>
                            <input id="name1" class="hanginputz"/>
                        </div>
                        <div class="hangz">
                            <span class="hangtitle">政策链接</span><br>
                            <input id="lianjie" class="hanginputz"/>
                        </div>
                        <div class="hangz">
                            <span class="hangtitle">发布时间</span><br>
                            <input id="fabushijian1" class="hanginputz" type="date"/>
                            <!--<div class="hanginputz" style="border: none"><el-date-picker id="fabushijian1" style="width: 100%" v-model="value2" type="datetime" placeholder="选择日期时间"></el-date-picker></div>-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button id="ShangBao1" class="btn">保存</button>
                <button id="QuXiao" class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width: 70vw;">
    <div class="modal-dialog" style="width: 70vw">
        <div class="modal-content" style="border-radius: 15px;width: 100%;">
            <div class="modal-header" style="background-color:white;color: black;border-top-left-radius: 15px;border-top-right-radius: 15px">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" >
                    &times;
                </button>
                <h4 class="modal-title">政策法规修改</h4>
            </div>

            <div class="modal-body" style="width: 100%;float:left;background-color: #F3F3F3;height: auto" id="xq1">
                <div id="type1">
                    <div class="hangz">
                        <span class="hangtitle">标题</span><br>
                        <input id="name2" class="hanginputz"/>
                    </div>
                    <div class="hangz">
                        <span class="hangtitle">政策文件</span><br>
                        <input id="wenjian1" class="hanginput" style="width: 73%!important;"/>
                        <input type="file" name="excelFile" id="excelFile1" style="display:none" multiple="multiple" onchange="fileUpload()">
                        <button id="glzmbtn1" onclick="selectFile1()" style="float: right;margin-top: 7px;width: 20%;margin-right: 5%" class="btn">点击上传</button>
                    </div>
                    <div class="hangz">
                        <span class="hangtitle">发布时间</span><br>
                        <input id="fabushijian2" class="hanginputz" type="date"/>
                        <!--<div class="hanginputz" style="border: none"><el-date-picker id="fabushijian2" style="width: 100%" v-model="value1" type="datetime" placeholder="选择日期时间"></el-date-picker></div>-->
                    </div>
                </div>
                <div id="type2">
                    <div class="hangz">
                        <span class="hangtitle">标题</span><br>
                        <input id="name3" class="hanginputz"/>
                    </div>
                    <div class="hangz">
                        <span class="hangtitle">政策链接</span><br>
                        <input id="lianjie1" class="hanginputz"/>
                    </div>
                    <div class="hangz">
                        <span class="hangtitle">发布时间</span><br>
                        <input id="fabushijian3" class="hanginputz" type="date"/>
                        <!--<div class="hanginputz" style="border: none"><el-date-picker id="fabushijian3" style="width: 100%" v-model="value2" type="datetime" placeholder="选择日期时间"></el-date-picker></div>-->
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button id="ShangBao2" class="btn">保存</button>
                <button data-dismiss="modal" id="QuXiao1" class="btn">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*new Vue({
        el: '#xq',
        data: {
            value1: '',
            value2: '',
        }
    })
    new Vue({
        el: '#xq1',
        data: {
            value1: '',
            value2: '',
        }
    })*/

    var svcHeader = Constants.path
    var zhen = localStorage.getItem('zhen');
    var qu = localStorage.getItem('qu');
    var qyid = localStorage.getItem('qyid');
    var qymc = localStorage.getItem('qymc');
    $(function () {
        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();
        //
        // //2.初始化Button的点击事件
        // var oButtonInit = new ButtonInit();
        // oButtonInit.Init();
    });
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#table').bootstrapTable({
                url: svcHeader+'pb/zcfgs/action/search',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                // search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                // strictSearch: true,
                // showColumns: true,                  //是否显示所有的列
                // showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                //height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                // showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                responseHandler:responseHandler,
                columns: [{
                    radio: true
                },
                    {
                        field: 'name',
                        align: 'center',
                        title: '标题'
                    }, {
                        field: 'dizhi',
                        align: 'center',
                        title: '文件名称',
                        formatter : function(value, row, index) {
                            var a = "";
                            if(row.type=="1"){
                                a=row.dizhi.substring(42)
                            }else{
                                a=row.dizhi
                            }
                            return a;
                        },
                    },{
                        field: 'fabushijian',
                        align: 'center',
                        title: '发布时间',
                    },{
                        field: 'operate',
                        title: '操作',
                        align: 'center',
                        events: operateEvents,
                        formatter: operateFormatter
                    },
                ],
            });
            initTableHeight()
        }
        function operateFormatter(value, row, index) {
            if(row.type == 1){
                return [
                    '<a class=" public am-btn gb"   href="javascript:void(0)"  title="发布成果" >',
                    '下载文件',
                    '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                ].join('');
            }else {
                return[
                    '<a class=" view am-btn gb"   href="javascript:void(0)"  title="查看成果" style="color: #16c519;">',
                    '打开链接',
                    '</a>&nbsp;&nbsp;&nbsp;&nbsp;',
                ].join('');
            }
        }
        oTableInit.queryParams = function (params) {
            if($("#key").val()==''&&zhen==""){
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageNo:params.offset/params.limit+1,
                    pageSize:params.limit,
                };
            }else if($("#key").val()==''&&zhen!=""){
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageNo:params.offset/params.limit+1,
                    pageSize:params.limit,
                    zhen:zhen,
                };
            }else if($("#key").val()!=''&&zhen==""){
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageNo:params.offset/params.limit+1,
                    pageSize:params.limit,
                    name:$("#key").val(),
                };
            }else{
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageNo:params.offset/params.limit+1,
                    pageSize:params.limit,
                    name:$("#key").val(),
                    zhen:zhen,
                };
            }
            return temp;
        };
        return oTableInit;
    };
    function   responseHandler(res) {
        $("#number").text(res.data.count)
        return {
            "rows": res.data.entities,
            "total":res.data.count
            //数据
        }
    }
    window.operateEvents = {
        //发布成果
        'click .public': function (e, value, row, index) {
            window.location.href=svcHeader+'FUGONGP/'+row.dizhi
        },

        //查看成果
        'click .view': function (e, value, row, index) {
            window.open(row.dizhi);
        },//查看报名
    };
    //新增
    $('body').on('hidden.bs.modal', '.modal', function () {
        $("#name").val('');
        $("#wenjian").val('');
        $("#name1").val('');
        $("#lianjie").val('');
        $("#fabushijian").val('');
        $("#fabushijian1").val('');
    })
    function clean(){
        $("#name").val('');
        $("#wenjian").val('');
        $("#name1").val('');
        $("#lianjie").val('');
    }
    $("#add").unbind('click').click(function () {
        $("#myModal1").modal('show');
    })
    $("#ShangBao1").unbind('click').click(function () {
        var obj={};
            if($("#name").val()!=''||$("#wenjian").val()!=''){
                 obj = {
                     'fabushijian': $("#fabushijian").val(),
                     'name': $("#name").val(),
                     'dizhi': $("#wenjian").val(),
                     'type':"1",
                     'qu':qu,
                     'zhen':zhen,
                     'userid':qyid,
                     'username':qymc
                };
            }else if($("#name1").val()!=''||$("#lianjie").val()!=''){
                obj = {
                    'fabushijian': $("#fabushijian1").val(),
                    'name': $("#name1").val(),
                    'dizhi': $("#lianjie").val(),
                    'type':"2",
                    'qu':qu,
                    'zhen':zhen,
                    'userid':qyid,
                    'username':qymc
                };
            }
            $.ajax({
                url:svcHeader+"pv/zcfgs",
                dataType:'json',
                type:'POST',
                contentType: 'application/json',
                data:JSON.stringify(obj),
                success:function (data) {
                    if(data.code=="200"){
                        alert("新增成功！")
                        $("#myModal1").modal('hide');
                        $("#table").bootstrapTable('destroy');
                        var oTable = new TableInit();
                        oTable.Init();
                    }else{
                        alert(data.msg)
                    }

                }
            })
    })
    //删除
    $("#delete").unbind('click').click(function(){
        var row = $.map($('#table').bootstrapTable(
            'getSelections'), function(row) {
            return row;
        })
        var x=row.length;
        var msg="删除";
        var y=0;
        var z=0;
        if(row.length==0){
            alert("请选择要删除的数据！")
        }else{
            for(var i=0;i<row.length;i++) {
                $.ajax({
                    url: svcHeader + "delete/zcfgs/"+row[i].id,
                    // dataType: 'json',
                    type: 'delete',
                    async: false,
                    success: function (data) {
                        if(data.code=='200'){
                            if(data.result==true){
                                y=y+1;
                            }else{
                                z=z+1;
                            }
                            if(y==x){
                                alert('已成功删除' + y + "条！")
                            }
                            $("#table").bootstrapTable('destroy');
                            var oTable = new TableInit();
                            oTable.Init();
                        }else{
                            alert(data.msg)
                        }
                    }
                })
            }
            if(y!=x){
                alert('已成功删除' + z + "条！失败"+y+'条！')
            }
        }
    })
    //修改
    $("#update").unbind('click').click(function(){
        var row = $.map($('#table').bootstrapTable(
            'getSelections'), function(row) {
            return row;
        });
        if(row.length==1){
                $("#myModal2").modal('show');
                if(row[0].type=="1"){
                    document.getElementById('type1').style.display=''
                    document.getElementById('type2').style.display='none'
                    $("#name2").val(row[0].name);
                    $("#fabushijian2").val(row[0].fabushijian);
                    $("#wenjian1").val(row[0].dizhi);
                    $("#ShangBao2").unbind('click').click(function () {
                        var obj = {
                            'id':row[0].id,
                            'name': $("#name2").val(),
                            'fabushijian': $("#fabushijian2").val(),
                            'dizhi': $("#wenjian1").val(),
                            'type':"1",
                            'qu':qu,
                            'zhen':zhen,
                            'userid':qyid,
                            'username':qymc
                        };

                        $.ajax({
                            url: svcHeader + "/pv/zcfgs/"+row[0].id,
                            dataType: 'json',
                            type: 'put',
                            contentType: 'application/json',
                            data: JSON.stringify(obj),
                            success: function (data) {
                                if(data.code=="200") {
                                    alert('修改成功！')
                                    $("#myModal2").modal('hide');
                                    $("#table").bootstrapTable('destroy');
                                    var oTable = new TableInit();
                                    oTable.Init();
                                }else{
                                    alert(data.msg)
                                }
                            }
                        })
                    })
                }else{
                    document.getElementById('type1').style.display='none'
                    document.getElementById('type2').style.display=''
                    $("#name3").val(row[0].name);
                    $("#fabushijian3").val(row[0].fabushijian);
                    $("#lianjie1").val(row[0].dizhi);
                    $("#ShangBao2").unbind('click').click(function () {
                        var obj = {
                            'id':row[0].id,
                            'name': $("#name3").val(),
                            'fabushijian': $("#fabushijian3").val(),
                            'dizhi': $("#lianjie1").val(),
                            'type':"2",
                            'qu':qu,
                            'zhen':zhen,
                            'userid':qyid,
                            'username':qymc
                        };

                        $.ajax({
                            url: svcHeader + "/pv/zcfgs/"+row[0].id,
                            dataType: 'json',
                            type: 'put',
                            contentType: 'application/json',
                            data: JSON.stringify(obj),
                            success: function (data) {
                                if(data.code=="200") {
                                    alert('修改成功！')
                                    $("#myModal2").modal('hide');
                                    $("#table").bootstrapTable('destroy');
                                    var oTable = new TableInit();
                                    oTable.Init();
                                }else{
                                    alert(data.msg)
                                }
                            }
                        })
                    })
                }

        }else{
            alert("只能选择一条")
        }
    })

    $("#btn_search").unbind('click').click(function () {
        $("#table").bootstrapTable('destroy');
        var oTable = new TableInit();
        oTable.Init();
    })

    function selectFile() {
        $("#excelFile").trigger("click");
    }
    function fileUpload() {
        var file = document.getElementById("excelFile");
        var fileObj = file.files[0];
        var formdata = new FormData();
        formdata.append('multipartFile', fileObj);
        $.ajax({
            url: svcHeader + "SaveSource",//这里写你的url
            type: 'POST',
            data: formdata,
            processData: false,
            contentType: false,
            success: function (data) {
                console.log(data)
                var wenjianming = data.data[0]
                $("#wenjian").val(wenjianming)
            },
            error: function (data) {
                alert("页面请求失败！");
            }
        })
    }
    function selectFile1() {
        $("#excelFile1").trigger("click");
    }
    function fileUpload1() {
        var file = document.getElementById("excelFile1");
        var fileObj = file.files[0];
        var formdata = new FormData();
        formdata.append('multipartFile', fileObj);
        $.ajax({
            url: svcHeader + "SaveSource",//这里写你的url
            type: 'POST',
            data: formdata,
            processData: false,
            contentType: false,
            success: function (data) {
                console.log(data)
                var wenjianming = data.data[0]
                $("#wenjian1").val(wenjianming)
            },
            error: function (data) {
                alert("页面请求失败！");
            }
        })
    }
</script>

</html>